﻿using UnityEngine;
using System.Collections;

public class powerUpBase : CanTakeDamage 
{
	public enum AttackType {Sniper=1, Always=2, Never=3, Rando=4}
	public AttackType attackType;
	
	public Motor mMotor;

	public GameObject Bullet;
	public float FireTimeout = .75f;
	public float FireTimer = 0;
	public int Value = 50;
	
	private float offSetX = 270;
	private float offSetY = 0;
	private float offSetZ = 0;
    private Transform Wave;
    private Manager difficultyManager = null;
	public GameObject explosion1;
	
	
	protected override void Start ()
	{
        Wave = GameObject.FindGameObjectWithTag("WaveManager").transform;
        foreach (Transform child in Wave)
        {
            if (child.gameObject.activeInHierarchy)
            {
                difficultyManager = child.gameObject.GetComponent<Manager>();
            }
        }
        if (difficultyManager.difficulty.enemyHealthAdder != 0 && difficultyManager.difficulty.enemyHealthMultiplier == 0)
        {
            Health += difficultyManager.difficulty.enemyHealthAdder;
        }
        else if (difficultyManager.difficulty.enemyHealthAdder == 0 && difficultyManager.difficulty.enemyHealthMultiplier != 0)
        {
            Health += Mathf.FloorToInt(Health*difficultyManager.difficulty.enemyHealthMultiplier);
        }
        else if (difficultyManager.difficulty.enemyHealthAdder != 0 && difficultyManager.difficulty.enemyHealthMultiplier != 0)
        {
            Health = (int)Mathf.Floor(difficultyManager.difficulty.enemyDamageMultiplier + 1f) + difficultyManager.difficulty.enemyHealthAdder;
        }
		base.Start ();
		

	}
	protected virtual void Update()
	{
		mMotor.Move();
	}

    protected virtual void activatePowerUp()
    {

    }
	
	public override void TakeDamage(int dmg)
	{
		ToggleShader();
		base.TakeDamage(dmg);
		Invoke("ToggleShader", .2f);
	}
	public void ToggleShader()
	{
		
		if (renderer.material.shader == Shader.Find("Transparent/Diffuse") || renderer.material.shader == Shader.Find("Transparent/Bumped Diffuse"))
		{
			//renderer.material.color = Color.red;
			renderer.material.shader = Shader.Find("Particles/Additive");
			
		}
		else if (renderer.material.shader == Shader.Find("Particles/Additive"))
		{
			//renderer.material.color = Color.white;
			renderer.material.shader = Shader.Find("Transparent/Diffuse");
		}
	}


	public override void Die()
	{

		GameObject burst = (GameObject) Instantiate( explosion1,transform.position,Quaternion.identity);
		Destroy(burst,1f);
		Debug.Log("power up destroyed");
		base.Die();
		activatePowerUp();

	}
}
